// facebook 实现一个函数， 它的输入是一个数组， 其中包含喜欢 该项目的人的姓名， 返回 值 是如下
// 格式
// [] "no one likes this"
// ["Peter"] "Peter likes this"
// ["Jacob", "Alex"] "Jacob and Alex like this"
// ["Max", "John", "Mark"] "Max, John and Mark like this"
// ["Max", "Jacob", "Mark", "Max"] "Alex, Jacob and 2 others like this"
function likes(names) {
    let templates = [
        'no one likes this',
        '{name} likes this',
        '{name} and {name} like this',
        '{name}, {name} and {name} like this',
        '{name}, {name} and {n} others like this'
    ]
    let idx = Math.min(names.length, 4);
    // console.log(idx);
    let str = templates[idx];
    for (let i = 0; i < names.length; i++) {
        str = str.replace("{name}", names[i])
    }
    return templates[idx].replace(/{name}|{n}/g, function(val) {
            // 返回值就是要替换的
            // console.log(val, '------');
            return val == '{names}' ? names.shift() : names.length;
        })
        // return templates[idx].replace("{name}", names[0])
        //根据数组的长度 取出相应的模板
    return str;
}
console.log(likes([]));
// likes(['段裕贤', '黄立新', '王昱坤', '熊太峰', '欧阳斐']);